<?php include "./mobile/view/header.inc.htm"; ?>

<div  style="width: 300px; margin: auto;">
	<form method="POST" id="login_form" action="pc/user-login.htm" class="form">
		<h2>用户登录</h2>
		<p><input type="text" placeholder="Email" name="account" style="width: 100%;"></p>
		<p><input type="password" placeholder="密码" name="password" style="width: 100%;"></p>
		<dl class="row margin">
			<dt><button type="submit" loading-text="正在登录..." class="blue big" style="width: 100%;">登录</button></dt>
			<dd class="right"><a href="user-create.htm">注册</a></dd>
		</dl>
	</form>
</div>

<?php include "./mobile/view/footer.inc.htm"; ?>

<script>

$(function() {
	var jform = $('#login_form');
	var jaccount = jform.find('input[name="account"]').focus();
	var jpassword = jform.find('input[name="password"]');
	var jsubmit = jform.find('button[type="submit"]');
	var jcreate = jform.find('button[type="button"]');
	jform.off('submit').on('submit', function() {
	//jsubmit.off('click').on('click', function() {
		if(!jaccount.val()) {
			jaccount.popover('请输入 Email').focus();
			return false;
		} else if(!jpassword.val()) {
			jpassword.popover('请输入密码').focus();
			return false;
		}
		var postdata = "account="+jaccount.val()+"&password="+$.md5(jpassword.val());
		jsubmit.button('loading');
		$.xpost(jform.attr('action'), postdata, function(code, message) {
			if(code == 0) {
				jsubmit.button('登录成功');
				$.pdata('myagreelist', message.myagreelist);
				//$.pdata('user', message);
				//$.cookie('bbs_token', message.token);
				setTimeout(function() {window.location='./mobile/';}, 1000);
			} else if(code > 0) {
				if(code == 1) jaccount.popover(message).focus();
				if(code == 2) jpassword.popover(message).focus();
				jsubmit.button('reset');
			} else if(code < 0) {
				alert(message);
				jsubmit.button('reset');
			}
		});
		return false;
	});
});
</script>